package com.wz.wiki.rocketmq;

import com.wz.wiki.websocket.WebSocketServer;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 王哲
 * @Contact 1121586359@qq.com
 * @ClassName VoteTopicRocketMQ.java
 * @create 2023年07月03日 下午5:22
 * @Description 点赞MQ消费端
 * @Version V1.0
 */
@Service
@RocketMQMessageListener(consumerGroup = "default", topic = "VOTE_TOPIC")
public class VoteTopicRocketMQ implements RocketMQListener<MessageExt>{

    private static final Logger LOG = LoggerFactory.getLogger(VoteTopicRocketMQ.class);

    @Resource
    public WebSocketServer webSocketServer;

    @Override
    public void onMessage(MessageExt messageExt) {
        byte[] body = messageExt.getBody();
        LOG.info("ROCKETMQ收到消息：{}", new String(body));
        webSocketServer.sendInfo(new String(body));
    }

}
